<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.pro.bean.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<% List rs = (List)request.getSession().getAttribute("viewlist"); %>
<%
	int requestPage = 1;
	if(request.getParameter("page") != null)
		requestPage = Integer.parseInt(request.getParameter("page"));
			
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <meta charset="utf-8">
	<link href="css/bootstrap.css" rel="stylesheet">
	<link rel="stylesheet" href="css/main.css">
	<link rel="stylesheet" href="css/datepicker.css">
	
	<script src="js/jquery.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/bootstrap-datepicker.js"></script>
  </head>
  
  <script>
$(function(){
var url = "servlet/GetAllGroupsServlet"
		
		$.post(url,null,function(data){
			objs = eval(data);
			$.each(objs,function(i,item){
				$("#groups").append("<option value='"+item.id+"'>"+item.name+"</option>");
			});
		});
	var d = true;
	
	$("#selectall").click(function(){
			$(".chkbox").each(function(){
				$(this).attr("checked","checked");
		});
	});
	
	$("#selectnone").click(function(){
		$(".chkbox").each(function(){
			$(this).attr("checked",false);
		});
	});
	
	$("#operation").change(function(){
		if(d)
		{
			$("#groups").attr("disabled","disabled");
			$("#inputgroupname").attr("disabled","disabled");
		}
		else
		{
			$("#groups").attr("disabled",false);
			$("#inputgroupname").attr("disabled",false);
		}
		d = !d;
	});
	
	$("#groups").change(function(){
		if($(this).val()=="-1")
			$("#inputgroupname").attr("disabled",false);
		else
			$("#inputgroupname").attr("disabled","disabled");
	});
	
	$("#go").click(function(){
		//alert($("#inputgroupname").val());
		if($("#operation").val() == "1")//追加到组
		{
			$(".chkbox").each(function(){
				if($(this).attr("checked"))
				{
					var url = "servlet/AddToGroupsServlet?cardid="
							+$(this).val()+"&groupid="+$("#groups").val()
							+"&newGroupName="+$("#inputgroupname").val();
					//alert(url);
					$.post(url,null,function(data){
						
					});
				}
			});
			alert("操作成功");
		}
		if($("#operation").val() == "2")
		{
			$(".chkbox").each(function(){
				if($(this).attr("checked"))
				{
					var url = "servlet/DeleteCardServlet?cardid="+$(this).val();
					//alert(url);
					$.post(url,null,function(data){
						
					});
				}
			});
			alert("删除成功");
			document.location.reload();
		}
	});
	
	  
});
  </script>
  <body>
    <div id="tablediv" style="height: 400px">
			<table id="table" class="table table-bordered table-hover">
				<tr>
					<th>
					</th>
					<th>
						姓名
					</th>
					<th>
						所有者
					</th>
					<th>
						所有者部门
					</th>
					<th>
						公司
					</th>
					<th>
						部门
					</th>
					<th>
						详细信息
					</th>
				</tr>
				<%
				System.out.println("requestpage="+requestPage+" size "+rs.size());
				if(rs != null) 
					for(int i = (requestPage-1)*9 ; i<rs.size() && i<(requestPage-1)*9+9 ; ++i)
					{
						Card_View cv = (Card_View)rs.get(i);
						out.println("<tr>");
						out.println("<td><input id=\"ckbox\" class=\"chkbox\" type=\"checkbox\" value=\""
								+cv.getCardid()+"\" />");
						out.println("<td>"+cv.getFirstname()+"</td>");
						out.println("<td>"+cv.getUsername()+"</td>");
						out.println("<td>"+cv.getUnitname()+"</td>");
						out.println("<td>"+cv.getCmp()+"</td>");
						out.println("<td>"+cv.getDept()+"</td>");
						out.println("<td><a href=\"servlet/LogServlet?cardid="
								+cv.getCardid()+"\"target=\"_blank\">详细信息</a></td>");
								
					}
				%>
				<!-- tr>
					<td>
						<input type="checkbox" class="chkbox"/>
					</td>
					<td>
						李四
					</td>
					<td>
						日本测试部
					</td>
					<td>
						张三疯
					</td>
					<td>
						日本测试部
					</td>
					<td>
						日本软件公司
					</td>
					<td>
						软件测试
					</td>
					<td>
						<a href="detail.html">详细信息</a>
					</td>
				</tr>
				 -->
			</table>
			<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                              
         </p>    
		</div>
		<br>
		<div id="downdiv">
			<p>
				<button id="selectall" type="button" class="btn btn-info btn-xs">
					&nbsp;&nbsp;&nbsp;全选&nbsp;&nbsp;&nbsp;
				</button>
				<button id="selectnone" type="button" class="btn btn-info btn-xs">
					取消全选
				</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				 共<%=rs.size()/9+1 %>页&nbsp;第<%=requestPage%>页        
          <%if(requestPage>1){ %>
            <a href="scypage/table.jsp?page=<%=requestPage-1%>">上一页</a>
            <%}else{ %>
                                    上一页
         <%}%>
         <%if(requestPage < rs.size()/9+1){ %>
        <a href="scypage/table.jsp?page=<%=requestPage+1%>">下一页</a>
            <%}else{ %>
                                   下一页
         <%}%>
				<select  name="txtGroupNam" size="1" id="operation"
					style="margin-left: 100px; width: 120px;">
					<option value="1">
						追加到组
					</option>
					<option value="2">
						全部删除
					</option>
				</select>
				<select name="groups" size="1" id="groups"
					style="width: 100px;">
					<option value="-1">
						输入新组名
					</option>
				</select>
				<input id="inputgroupname" name="groupname" style="width:90px"/>
				<button id="go" style="margin-left:20px" type="button"
					class="btn btn-primary btn-sm">
					&nbsp;&nbsp;&nbsp;执行&nbsp;&nbsp;&nbsp;
				</button>
			</p>
		</div>
  </body>
</html>
